{extend name="public:base" /}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <div class="row search-form">
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="yearQuarter" class="form-control form-control-lg">
                                    <option value="">请选择时间段</option>
                                    {volist name="year_quarter_list" id="vo"}
                                    <option value="{$vo.year}-{$vo.quarter}" {:input('yearQuarter') == $vo['year'].'-'.$vo['quarter'] ? 'selected' : ''}>{$vo.desc}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <button type="button" class="btn btn-primary btn-lg screen-btn">搜索</button>
                                <button type="button" class="btn btn-primary btn-lg excel-btn">导出</button>
                                <button type="button" onclick="history.back()" class="btn btn-lg" style="height: 2.1rem; margin-left: 10px;">返回</button>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th>类别</th>
                                <th>明细科目</th>
                                <th>发票种类</th>
                                <th>发票明细</th>
                                <th>发票数量</th>
                                <th>发票金额</th>
                                <th>时间段</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.type_name}</td>
                                <td>{$vo.title}</td>
                                <td>{$vo.desc}</td>
                                <td>{$vo.price_text}</td>
                                <td>{$vo.count}</td>
                                <td>{$vo.all_price}</td>
                                <td>{$vo.year}年第{$vo.quarter}季度</td>
                                <td>
                                    <a href="{:url(doTaxDeduction, ['id' => $vo.id])}" class="btn btn-white btn-sm"><i class="iconfont icon-edit"></i> 编辑 </a>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        {if !empty($list)}{$list->render()}{/if}
                    </div>

                </div>
            </div>
        </div>

    </div>
</div>
{/block}

{block name="js"}
<script>
    $(function () {
        var id;
        // 点击按钮触发文件选择框
        $('.upload-btn').on('click', function () {
            id = $(this).data('id');
            $('.upload-file').click();
        });

        // 监听文件选择变化
        $('.upload-file').on('change', function (e) {
            var file = this.files[0];
            if (!file) return;

            // 检查文件类型
            var allowedTypes = ['application/pdf', 'image/png', 'image/jpeg'];
            if (!allowedTypes.includes(file.type)) {
                alert('只能上传 PDF、PNG 或 JPG 格式的文件');
                return;
            }

            // 可选：限制文件大小，比如最大 5MB
            var maxSizeMB = 5;
            if (file.size > maxSizeMB * 1024 * 1024) {
                alert('文件大小不能超过 ' + maxSizeMB + 'MB');
                return;
            }

            // 构造 FormData 用于上传
            var formData = new FormData();
            formData.append('file', file);
            formData.append('id', id);

            // 上传文件（替换 URL 为你自己的上传接口）
            $.ajax({
                url: '/upload/uploadFile/uploadFile',
                type: 'POST',
                data: formData,
                contentType: false,
                processData: false,
                success: function (res) {
                    if(res.status == 1){
                        layer.msg(res.info, {icon: 1, time: 1000}, function () {
                            window.location.reload();
                        })
                    }else{
                        layer.msg(res.info, {icon: 2, time: 1000}, function () {
                            window.location.reload();
                        })
                    }
                },
                error: function (err) {
                    // 上传失败逻辑
                    layer.msg(res.info, {icon: 2, time: 1000}, function () {
                        window.location.reload();
                    })
                }
            });
        });
    });
</script>

{/block}